package com.ruoyi.employee1.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.employee1.domain.ErpEmployee;
import com.ruoyi.employee1.service.IErpEmployeeService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 员工Controller
 * 
 * @author ruoyi
 * @date 2025-07-28
 */
@RestController
@RequestMapping("/employee1/employee1")
public class ErpEmployeeController extends BaseController
{
    @Autowired
    private IErpEmployeeService erpEmployeeService;

    /**
     * 查询员工列表
     */
    @PreAuthorize("@ss.hasPermi('employee1:employee1:list')")
    @GetMapping("/list")
    public TableDataInfo list(ErpEmployee erpEmployee)
    {
        startPage();
        List<ErpEmployee> list = erpEmployeeService.selectErpEmployeeList(erpEmployee);
        return getDataTable(list);
    }

    /**
     * 导出员工列表
     */
    @PreAuthorize("@ss.hasPermi('employee1:employee1:export')")
    @Log(title = "员工", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ErpEmployee erpEmployee)
    {
        List<ErpEmployee> list = erpEmployeeService.selectErpEmployeeList(erpEmployee);
        ExcelUtil<ErpEmployee> util = new ExcelUtil<ErpEmployee>(ErpEmployee.class);
        util.exportExcel(response, list, "员工数据");
    }

    /**
     * 获取员工详细信息
     */
    @PreAuthorize("@ss.hasPermi('employee1:employee1:query')")
    @GetMapping(value = "/{employeeId}")
    public AjaxResult getInfo(@PathVariable("employeeId") Long employeeId)
    {
        return success(erpEmployeeService.selectErpEmployeeByEmployeeId(employeeId));
    }

    /**
     * 新增员工
     */
    @PreAuthorize("@ss.hasPermi('employee1:employee1:add')")
    @Log(title = "员工", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ErpEmployee erpEmployee)
    {
        return toAjax(erpEmployeeService.insertErpEmployee(erpEmployee));
    }

    /**
     * 修改员工
     */
    @PreAuthorize("@ss.hasPermi('employee1:employee1:edit')")
    @Log(title = "员工", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ErpEmployee erpEmployee)
    {
        return toAjax(erpEmployeeService.updateErpEmployee(erpEmployee));
    }

    /**
     * 删除员工
     */
    @PreAuthorize("@ss.hasPermi('employee1:employee1:remove')")
    @Log(title = "员工", businessType = BusinessType.DELETE)
	@DeleteMapping("/{employeeIds}")
    public AjaxResult remove(@PathVariable Long[] employeeIds)
    {
        return toAjax(erpEmployeeService.deleteErpEmployeeByEmployeeIds(employeeIds));
    }
}
